<?php
	session_start();
	require ("lib/mconnect.php");
	require ("models/muser.php");
	$loi = "";
	if(isset($_POST["ok"])){
		$u = $p = "";
		if($_POST["username"] == null){
			$loi[] = "Ban chua nhap username";
		}else{
			$u = $_POST["username"];
		}
		if($_POST["pass"] == null){
			$loi[] = "Ban chua nhap password";
		}else{
			$p = $_POST["pass"];
		}
		if($u && $p){
			$login = new muser;
			$login->setuser($u);
			$login->setpass($p);
			$data = $login->check();
			if($data == false){
				$loi[] = "Ban nhap sai, vui long nhap lai";
			}else{
				/*$_SESSION["user"] = $data["username"];
				$_SESSION["id"] = $data["user_id"];
				$_SESSION["level"] = $data["level"];
				header("location: index.php");
				exit();*/
				$_SESSION["se_user"] = $data["username"];
				$_SESSION["se_id"] = $data["id"];
				$_SESSION["se_level"] = $data["level"];
				header("location: index.php");
				exit();
			}
		}
	}
	require_once ("views/login/login.php");
?>